package day_2023_7_to_10;

import java.util.HashSet;
import java.util.Set;

/**
 * @author haomin
 * @date 2023/08/07 23:57
 **/
public class Day_8_8 {
    class Solution {
        public int maxProfit(int[] prices) {
            if(prices.length == 0) return 0;
            int ans = 0, minBuy = prices[0];
            for(int i = 1; i < prices.length; ++i) {
                if(minBuy > prices[i]) minBuy = prices[i];
                ans = Math.max(ans, prices[i] - minBuy);
            }
            return ans;
        }
    }
    class Solution2 {
        Set<String> res = new HashSet<>();
        public String[] permutation(String s) {
            if(s.length() == 0) return new String[0];
            char[] arr = s.toCharArray();
            dfs(arr, new StringBuffer(), s, new int[arr.length]);
            return res.toArray(new String[0]);
        }
        public void dfs(char[] arr, StringBuffer sb, String s, int[] flag) {
            if(sb.toString().length() == s.length()){
                res.add(sb.toString());return;
            }
            for(int i = 0; i < arr.length; ++i) {
                if(flag[i] == 1) continue;
                sb.append(arr[i]);
                flag[i] = 1;
                dfs(arr, sb, s, flag);
                sb.deleteCharAt(sb.length()-1);
                flag[i] = 0;
            }

        }
    }
}